package com.cnfilm.web.code;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;

/**
 * Code model.
 */
@SuppressWarnings("serial")
public class Code extends Model<Code> {
	
	public static final Code dao = new Code();
	
	
	public static List<Code> getCodeByType(String type){
		 List<Code> codeList = null;
		 String sql = "select * from code where type=? order by code asc";
		 codeList = Code.dao.find(sql, type);
		 return codeList;
	}
	
	public static String getNameByCodeAndType(String vtype,String code){
		Code codeObj = null;
		String sql = "select * from code where type=? and code=?";
		codeObj = Code.dao.findFirst(sql, vtype,code);
		if(codeObj!=null){
			return codeObj.getStr("name");
		}
		return "";
	}
	
	public static String getContentByCodeAndType(String vtype,String code){
		Code codeObj = null;
		String sql = "select * from code where type=? and code=?";
		codeObj = Code.dao.findFirst(sql, vtype,code);
		if(codeObj!=null){
			return codeObj.getStr("content");
		}
		return "";
	}
	
	public static List<Code> getCountByTypeAndFid(String type,String fid){
		String sql = "select (select count(1) from video B where B.vtype = A.code and B.fid=?) as num,A.code,A.name from code A where A.type=?";
		List<Code> codeList = Code.dao.find(sql,fid,type);
		return codeList;
	}
}